package unit11;

import java.awt.EventQueue;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;

public class LoggingImageViewer {
	public static void main(String[] args) {
		if(System.getProperty("java.util.logging.cinfig.class")==null
				&&System.getProperty("java.util.logging.cinfig.file")==null){
			try {
				Logger.getLogger("com.javase.corejava").setLevel(Level.ALL);
				final int LOG_ROTATION_COUNT=10;
				Handler handler=new FileHandler("%h/LoggingImageViewer.log",0,LOG_ROTATION_COUNT);
				Logger.getLogger("com.javase.corejava").addHandler(handler);
			} catch (IOException e) {
				// TODO: handle exception
				Logger.getLogger("com.javase.corejava").log(Level.SEVERE, "Can't create log file handler",e);
			}
		}
		EventQueue.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Handler windowHandler=new WindowHandler();
				windowHandler.setLevel(Level.ALL);
				Logger.getLogger("com.javase.corejava").addHandler(windowHandler);
				 
				JFrame f=new ImageViewerFrame();
				f.setTitle("Logging");
				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
				Logger.getLogger("com.javase.corejava").fine("Showing frame");
				f.setVisible(true);
			}
		});
	}
}
